package com.itheima.demo7;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerDemo1 {
    public static void main(String[] args) throws IOException {
        //TCP协议，接收数据

        //1.创建对象ServerSocker
        ServerSocket sc = new ServerSocket(10086);

        //2.监听客户端的连接
        Socket socket = sc.accept();

        //3.从连接通道中获取输入流读取的数据
        //创建字符缓冲流进行数据读取
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));

        int b ;
        while ((b = br.read()) != -1){
            System.out.print((char)b);
        }


        //4.释放资源
        socket.close();
        sc.close();


    }
}
